from commands import add, admin
import commands
     
@admin
def rambomode(connection):
    if connection.protocol.rambomode == True:
        connection.protocol.send_chat('Rambo Mode Disabled.')
        connection.protocol.rambomode = False
    else:
        if connection.protocol.rambomode is None:
            connection.protocol.rambomode = set()
        connection.protocol.send_chat('Rambo Mode Enabled.')
        connection.protocol.rambomode = True
add(rambomode)

def apply_script(protocol, connection, config):
    class OneHitConnection(connection):
        amrambo = False
        def take_flag(self):
            if self.protocol.rambomode == True:
                self.amrambo = True
                self.refill()
                self.send_chat('RAMBO MODE ACTIVATED')
            return connection.take_flag(self)
        def drop_flag(self):
            if self.protocol.rambomode == True:
                self.amrambo = False
            return connection.drop_flag(self)
        def on_hit(self, hit_amount, player):
            value = connection.on_hit(self, hit_amount, player)
            if value is not None:
                return value
            if self.protocol.rambomode == True:
                if self.amrambo == True:
                    return hit_amount * 100
                    player.send_chat('RAMBOWNED!')
                if player.amrambo == True:
                    return hit_amount * 0.25
        def on_flag_capture(self):
            if self.protocol.rambomode == True:
                self.amrambo = False
            return connection.on_flag_capture(self)
    class OneHitProtocol(protocol):
        rambomode = None
    return OneHitProtocol, OneHitConnection